/*
 * Package il.ac.biu.cs.grossmm.api.data
 * File NodeManipulator.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
 * MA  02110-1301, USA.
 */

package il.ac.biu.cs.grossmm.api.flow;

import il.ac.biu.cs.grossmm.api.OperationFailedException;
import il.ac.biu.cs.grossmm.api.data.Node;
import il.ac.biu.cs.grossmm.api.data.Nodeset;
import il.ac.biu.cs.grossmm.api.data.Property;

/**
 * Provides tools to read and updare data within a data-node
 */
public interface NodeManipulator extends NodeInspector {
	/**
	 * Changes value of a node property. Equality test is not performed by the
	 * data engine: a notification about update will be sent when transaction is
	 * commeted even if the new (specified) value is equal to the old value.
	 * 
	 * @param <N>
	 *            node interface
	 * @param <V>
	 *            value property class
	 * @param node
	 *            the node
	 * @param property
	 *            property within this node
	 * @param value
	 *            the new value
	 * @throws OperationFailedException
	 */
	<N, V> void setValue(Node<N> node, Property<N, V> property, V value)
		throws OperationFailedException;

	/**
	 * Changes value of a node property. Verifies first that the specified value
	 * differs form the current value. If yes, the value updated and event
	 * notification is guaranteed to be sent when transaction is committed. If
	 * no, the method returns without any effect.
	 * 
	 * 
	 * @param <N>
	 *            node interface
	 * @param <V>
	 *            value property class
	 * @param node
	 *            the node
	 * @param property
	 *            property within this node
	 * @param value
	 *            the new value
	 * @throws OperationFailedException
	 */
	<N, V> void setAndCheck(Node<N> node, Property<N, V> property, V value)
		throws OperationFailedException;

	/**
	 * Creates a new sub-node and adds it to the specidied node-set of the
	 * specified node
	 * 
	 * @param <N>
	 *            node interface
	 * @param <S>
	 *            value property class
	 * @param node
	 *            the node
	 * @param nodeSet
	 *            node set to add the node too
	 * @return newly created sub-node, added to the specified node-set of the
	 *         specified node
	 * @throws OperationFailedException
	 */
	<N, S> Node<S> createSubnode(Node<N> node, Nodeset<N, S> nodeSet)
		throws OperationFailedException;

	/**
	 * Copies all data from source node (subtree) to destination node (subtree),
	 * where source node and destination node belong to the same node type.
	 * 
	 * @param <N>
	 *            node interface of the both nodes
	 * @param inspector
	 *            event inspector which can be used to inspect the source node
	 * @param src
	 *            the source node
	 * @param dst
	 *            the destination node
	 */
	<N> void copyNode(NodeInspector inspector, Node<N> src, Node<N> dst);

	/**
	 * Removes a sub-node from the specified node-set of the specified node.
	 * This method cannot be used to remove a root (which can be deleted by
	 * deactivating notifications, unsubscribing or removing data from
	 * publication point)
	 * 
	 * @param <S>
	 *            sub-node interface
	 * @param subnode
	 *            the sub-node to remove
	 * 
	 * @throws OperationFailedException
	 */
	<S> void removeSubnode(Node<S> subnode) throws OperationFailedException;
}
